<?php

class SecretaryController extends Zend_Controller_Action
{

    public function init()
    {
        $this->_helper->redirector->setUseAbsoluteUri(true);
        $this->_mySession = Zend_Registry::get('session'); 
    }

    public function indexAction()
    {
    }
    
    public function autocompleteCityAction()
    {
        $this->_helper->layout()->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);

        if (!$this->getRequest()->isXmlHttpRequest()) {
            return;
        }

        $address = new Application_Model_DbTable_Address();
        $rows = $address->getCity($this->_getParam('term', ''));
        $result = array();
        if(!empty($rows)) {
            foreach($rows as $row) {
               $result[] = $row->city;
            }
        }
        echo Zend_Json::encode($result);
    }

    public function autocompleteZipCodeAction()
    {
        $this->_helper->layout()->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);

        if (!$this->getRequest()->isXmlHttpRequest()) {
            return;
        }

        $address = new Application_Model_DbTable_Address();
        $rows = $address->getZipCode($this->_getParam('term', ''));
        $result = array();
        if(!empty($rows)) {
            foreach($rows as $row) {
                $result[] = $row->zipCode;
            }
        }
        echo Zend_Json::encode($result);
    }

    public function autocompleteUsAction()
    {
        $this->_helper->layout()->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);

        if (!$this->getRequest()->isXmlHttpRequest()) {
            return;
        }

        $us = new Application_Model_DbTable_Us();
        $rows = $us->getUs($this->_getParam('term', ''));
        $result = array();
        if(!empty($rows)) {
            foreach($rows as $row) {
                $result[] = $row->us;
            }
        }
        echo Zend_Json::encode($result);
    }
}
